home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2526 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  47 lines

  1. Newsgroups: comp.lang.c,gnu.gcc.help
  2. Path: info.physics.utoronto.ca!olivers
  3. From: olivers@helios.physics.utoronto.ca (Oliver Schonborn)
  4. Subject: [Q] WEIRD macro bug only when compiling with GCC
  5. Message-ID: <DLKABL.KGK@info.physics.utoronto.ca>
  6. Nntp-Posting-Host: helios.physics.utoronto.ca
  7. Sender: news@info.physics.utoronto.ca (System Administrator)
  8. Organization: University of Toronto - Dept. of Physics
  9. Date: Mon, 22 Jan 1996 02:45:21 GMT
  10.  
  11.  
  12. Hi folks,  I defined the following macro, *which works
  13. FINE* with the HP cc compiler:
  14.  
  15.     #define SQR(X,A)  (A=(X),(A*A))
  16.  
  17. I call it for example by
  18.  
  19.    float ans,f,dx,dy;
  20.    int i,j;
  21.    dx=1;dy=0.335389;
  22.    for (i=0;i<10;i++) {
  23.        for (j=0;j<10;j++) {
  24.            ans = SQR( i*dx, f) + SQR( j*dy, f);
  25.        }
  26.    }
  27.  
  28. The macro *works FINE* when I compile with our HP compiler,
  29. cc: it prints out one hundred different numbers.  BUT when
  30. I use gcc to compile, instead what it prints is double the
  31. result of the first SQR on the line, ie  SQR( i*dx, f) * 2.
  32. Why isn't (a=b, b*b)+(a=c, c*c) equal to b*b+c*c for GCC?
  33.  
  34. Although I've decided to implememt the macro by a function
  35. instead (float sqr(float x) {return x*x;}), I'm curious to
  36. know what is wrong with the macro I wrote.  Anyone have a
  37. clue?
  38.  
  39. Thanks a lot!
  40.  
  41. Oliver
  42. -- 
  43.   _________________________________........----------------,
  44.  /\  OliverS@physics.utoronto.ca                            \
  45.  \_|  Condensed-Matter/Quantum-Optics Theory Group           )
  46.    /  Physics Dept University of Toronto -- Canada          /
  47.